package observe;

import java.util.ArrayList;

public class WeatherData implements Subject{

    private float temperature;
    private float pressure;
    private float humidity;

    private ArrayList<Observe> observes;

    public WeatherData() {
        this.observes = new ArrayList<Observe>();
    }
    //更新
    public void changeData(float temperature, float pressure, float humidity){
        this.temperature = temperature;
        this.pressure = pressure;
        this.humidity = humidity;
        notifyObserve();
    }

    @Override
    public void registerObserve(Observe o) {
        if (null != o) {
            observes.add(o);
        }
    }

    @Override
    public void removeObserve(Observe o) {
        if (observes.contains(o)){
            observes.remove(o);
        }
    }

    @Override
    public void notifyObserve() {
        for (int i=0; i<observes.size(); i++){
            observes.get(i).update(this.temperature, this.pressure,this.humidity);
        }
    }


}
